#!/bin/zsh
zmodload zsh/param/private
zmodload -F zsh/zutil b:zparseopts

local -a reply=()
local REPLY=

local -A opts_pre=()
zparseopts -A opts_pre -D -- h -help

if ! (( $# )); then
  .znap.help
  return
fi

private _P__cmd=$1
shift

local -A opts_pre=() opts_post=()
zparseopts -A opts_post -D -- h -help

private _P__func=.znap.$_P__cmd
if [[ -v functions[$_P__func] ]]; then
  if (( ${#opts_pre} || ${#opts_post} )); then
    .znap.help $_P__cmd
  else
    $_P__func $@
  fi
else
  print -u2 "znap: unknown command: $_P__cmd"
  .znap.help
  return $(( sysexits[(i)USAGE] + 63 ))
fi
